package com.googlecode.recycled.lang.jse.api;

import com.google.common.base.Function;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.UnhandledException;

import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;

public class InternetAddresses {

    private InternetAddresses() {
    }

    public static final Function<String, InternetAddress> F_STRING_INTERNETADDRESS = new Function<String, InternetAddress>() {
        @Override
        public InternetAddress apply(String address) {
            if (StringUtils.isBlank(address)) {
                return null;
            }
            try {
                return new InternetAddress(address);
            } catch (AddressException e) {
                throw new UnhandledException(e);
            }
        }

    };

    public static InternetAddress asInternetAddress(String address) {
        return F_STRING_INTERNETADDRESS.apply(address);
    }

}
